﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Adittional
using DO.Domain.Repositories;
using DO.Common.DTOs.Person;

namespace DO.Domain.Entities
{
    public class Person:EntityBase
    {
        protected Person() { }

        public virtual string FirstName1 { get; protected set; }
        public virtual string FirstName2 { get; protected set; }
        public virtual string LastName1 { get; protected set; }
        public virtual string LastName2 { get; protected set; }

        public static Person Create(IRepositoryLocator repositoryLocator, PersonDTO dataTransferObject)
        {
            var instance = new Person
            {
                FirstName1 = dataTransferObject.FirstName1,
                FirstName2 = dataTransferObject.FirstName2,
                LastName1 = dataTransferObject.LastName1,
                LastName2 = dataTransferObject.LastName2
            };

            repositoryLocator.Save(instance);
            return instance;
        }

        public void Update(IRepositoryLocator repositoryLocator, PersonDTO dataTransferObject)
        {
            this.UpdateValidated(repositoryLocator, dataTransferObject);
            this.FirstName1 = dataTransferObject.FirstName1;
            this.FirstName2 = dataTransferObject.FirstName2;
            this.LastName1 = dataTransferObject.LastName1;
            this.LastName2 = dataTransferObject.LastName2;

            repositoryLocator.Update(this);
        }

        private void UpdateValidated(IRepositoryLocator repositoryLocator, PersonDTO dataTransferObject)
        {
            return;
        }
    }
}
